package com.example.demo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        findViewById(R.id.activity_login_btn_login).setOnClickListener(this);
        findViewById(R.id.activity_login_btn_cancel).setOnClickListener(this);
        findViewById(R.id.activity_login_btn_register).setOnClickListener(this);
    }
    //描述控件被点击之后的逻辑
    @Override
    public void onClick(View v) {
        String name = ((EditText)findViewById(R.id.activity_login_et_name)).getText().toString().trim();
        switch (v.getId()){
            case R.id.activity_login_btn_login:
                Intent intent = new Intent(LoginActivity.this,IndexActivity.class);
                intent.putExtra("loginname",name);
                startActivity(intent);
                finish();
                break;
            case R.id.activity_login_btn_cancel:
                finish();
            case R.id.activity_login_btn_register:
                Intent intent_register = new Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent_register);
                finish();
        }
    }
}
